{% extends "nav.html" %}
{% block little %}存储-添加主机{% endblock %}
{% block content %}
    <!-- Main Content -->
    <div class="container-fluid">
        <div class="side-body">
            <div class="page-title">
                <span class="title">光交端口数据表</span>
                <div style="margin-left: 2%;">
                    <h4>报错信息说明:</h4>
                    <h5 style="margin-left: 2%;">1.Loss sync，Loss sig，Link-fail这三个错误在链路初始化的过程中都会产生。当链路不稳定时候，通常这些错误计数器比较高。</h5>
                    <h5 style="margin-left: 2%;">2.Enc_out和Crc_err两个计数器同时比较高，通常需要更换GBIC/SFP。</h5>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <div class="card">
                        <div class="card-header">
                        </div>
                        <div  class="col-xs-8">
                            <table id = "add_tablist"class="datatable table table-striped " cellspacing="0" >
                                <tbody>
                                <tr style="height:50px">
                                    <th  ><h4>光交：</h4></th>
                                    <th >
                                        <select class="form-control" id="caiji_san">
                                            {% for i in data %}
                                                <option name="{{ i.id }}">{{ i.ip }}</option>
                                            {% endfor %}
                                        </select>
                                    </th>
                                    <th><h4>槽位:</h4></th>
                                    <th><select class="form-control" id="caiji_slot">
                                    </select></th>
                                    <th><h4>端口：</h4></th>
                                    <th><select class="form-control" id="caiji_port">

                                    </select></th>
                                    <th><button type="button" class="btn btn-success" id="san_err_get_shuju" style="margin-top: 0px;">查询</button></th>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div id="port_tables" class="col-xs-12"  style="height:400px;"></div>
                    </div>
                    <div>
                        <table class="table  table-bordered">
                                            <thead>
                                            <tr>
                                                <th>wwn</th>
                                                <th>enc_in</th>
                                                <th>crc_err</th>
                                                <th>crc_g_eof</th>
                                                <th>two_shrt</th>
                                                <th>two_long</th>
                                                <th>bad_eof</th>
                                                <th>enc_out</th>
                                                <th>disc_c3</th>
                                                <th>link_fail</th>
                                                <th>loss_sync</th>
                                                <th>loss_sig</th>
                                                <th>frjt</th>
                                                <th>fbsy</th>
                                                <th>timeout_tx</th>
                                                <th>timeout_rx</th>
                                                <th>RX_Power</th>
                                                <th>TX_Power</th>
                                                <th>log_time</th>
                                            </tr>
                                            </thead>
                                            <tbody id="err_port_mess">
                                            </tbody>
                                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>

{% endblock %}
{% block js %}
    <script>
        $("#caiji_san").change(function () {
            var sanid = $("#caiji_san").find("option:selected").attr("name");
            $.ajax({
                url: "{% url "caiji_san_port" %}",
                type: 'POST',
                data:{id:sanid},
                success: function(data){
                    var obj = JSON.parse(data);
                    if(obj.status){
                        var a = obj.slot
                        var b = obj.port
                        $("#caiji_slot").empty()
                        $("#caiji_port").empty()

                        for(var i = 0;i < a.length; i++){
                            $("#caiji_slot").append(a[i])
                        };
                        for (var i = 0;i < b.length; i++){
                            $("#caiji_port").append(b[i])
                        };
                    }else{
                    };
                }
            });
        });
        var myChart = echarts.init(document.getElementById('port_tables'));
        // 过渡---------------------

        myChart.setOption({
            title: {
                text: '光交报错图'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data:[]
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: []
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name:'linkfail',
                    type:'line',
                    stack: '总量',
                    data:[]
                },
                {
                    name:'enc_in',
                    type:'line',
                    stack: '总量',
                    data:[]
                },
                {
                    name:'crc_err',
                    type:'line',
                    stack: '总量',
                    data:[]
                },
                {
                    name:'loss_sig',
                    type:'line',
                    stack: '总量',
                    data:[]
                },
                {
                    name:'enc_out',
                    type:'line',
                    stack: '总量',
                    data:[]
                },
                {
                    name:'loss_sync',
                    type:'line',
                    stack: '总量',
                    data:[]
                }
            ]
        });

        $("#san_err_get_shuju").click(function () {
            var sanid = $("#caiji_san").find("option:selected").attr("name");
            var slot = $("#caiji_slot").find("option:selected").text();
            var port = $("#caiji_port").find("option:selected").text();
            $("#err_port_mess").empty()
            myChart.showLoading({
                text: '正在努力的读取数据中...',    //loading话术
            });
            $.ajax({
                url: "{% url "san_err_get_shuju" %}",
                type: 'GET',
                data:{sanid:sanid,slot:slot,port:port},
                success: function(data){
                    var obj = JSON.parse(data);
                    if(obj.status){
                        var name = obj.name
                        var linkfail = obj.linkfail
                        var time = obj.get_time
                        var enc_in = obj.enc_in
                        var crc_err = obj.crc_err
                        var loss_sig = obj.loss_sig
                        var enc_out = obj.enc_out
                        var loss_sync = obj.loss_sync
                        myChart.hideLoading();
                        myChart.setOption({
                            legend: {
                                data:name
                            },
                            xAxis: {
                                type: 'category',
                                boundaryGap: false,
                                data: time
                            },
                            series: [
                                {
                                    name:'linkfail',
                                    type:'line',
                                    stack: '总量',
                                    data:linkfail
                                },
                                {
                                    name:'enc_in',
                                    type:'line',
                                    stack: '总量',
                                    data:enc_in
                                },
                                {
                                    name:'crc_err',
                                    type:'line',
                                    stack: '总量',
                                    data:crc_err
                                },
                                {
                                    name:'loss_sig',
                                    type:'line',
                                    stack: '总量',
                                    data:loss_sig
                                },
                                {
                                    name:'enc_out',
                                    type:'line',
                                    stack: '总量',
                                    data:enc_out
                                },
                                {
                                    name:'loss_sync',
                                    type:'line',
                                    stack: '总量',
                                    data:loss_sync
                                },
                            ]
                        });
                        $("#err_port_mess").append(obj.html)
                    }else{
                        myChart.showLoading();
                        alert(obj.error)
                    };
                }
            });
        });

    </script>
{% endblock %}